package cn.sciento.starter.sms.support;

import cn.sciento.core.exception.CommonException;
import com.github.qcloudsms.SmsMultiSender;
import com.github.qcloudsms.SmsMultiSenderResult;
import cn.sciento.starter.sms.entity.SmsConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class QcloudSmsSupporter {
  private static final Logger logger = LoggerFactory.getLogger(QcloudSmsSupporter.class);
  
  public static SmsMultiSender multiSender(SmsConfig smsConfig) {
    return new SmsMultiSender(Integer.parseInt(smsConfig.getAccessKey()), smsConfig.getAccessKeySecret());
  }
  
  public static SmsMultiSenderResult sendSms(SmsMultiSender smsMultiSender, String idd, String[] receiverAddress, String templateId, String[] params, String smsSign) {
    try {
      return smsMultiSender.sendWithParam(idd, receiverAddress, Integer.parseInt(templateId), params, smsSign, "", "");
    } catch (Exception e) {
      logger.error("Unable to send sms : {0}", e.fillInStackTrace());
      throw new CommonException(e);
    } 
  }
}
